package com.xxzb.pack0722.拼接;

import com.xxzb.bean.Dept;
import com.xxzb.bean.Emp;
import com.xxzb.db.DBManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class EmpDAO {
    private Connection conn;
    private PreparedStatement ps;
    private ResultSet rs;
    public List<Emp> find() throws Exception {
        List<Emp> list=new ArrayList<>();
        conn= DBManager.getConnection();
        String sql="select * from gaofeng2207.emp,gaofeng2207.dept where emp.deptNo=dept.deptNo and empstate=1";
        ps=conn.prepareStatement(sql);
         rs = ps.executeQuery();
         while (rs.next()){
             int empNo=rs.getInt(1);
             String ename=rs.getString(2);
             String job=rs.getString(3);
             int mgr=rs.getInt(4);
             String hireDate=rs.getString(5);
             Double sal=rs.getDouble(6);
             Double comm=rs.getDouble(7);
             int deptno=rs.getInt(8);
             String dname=rs.getString(11);
             String loc=rs.getString(12);
             Dept dept=new Dept(deptno,dname,loc);
             Emp emp=new Emp(empNo,ename,job,mgr,hireDate,sal,comm,deptno,1,dept);
             list.add(emp);
         }
         return list;
    }
}
